package at.fhj.mobsecdev.cookit.util;

import android.app.Activity;
import android.view.ViewGroup.LayoutParams;
import android.widget.EditText;
import android.widget.LinearLayout;
import at.fhj.mobsecdev.cookit.R;

/**
 * Implements the factory pattern to creates an IngredientControl
 */
public class IngredientControlTupleFactory {
	private IngredientControlTupleFactory() {}
	
	/**
	 * Generates an IngredientControl for the given activity
	 * @param activity the activity
	 * @return the created tuple
	 */
	public static IngredientControlTuple get(Activity activity) {
		LinearLayout amountIngredientTuple = new LinearLayout(activity);
		EditText newAmount = new EditText(activity);
		EditText newIngredient = new EditText(activity);
		
		LayoutParams amountLayoutParams =  new LinearLayout.LayoutParams(54,LayoutParams.WRAP_CONTENT, 10f);
		LayoutParams ingredientLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 5f);
		
		newAmount.setLayoutParams(amountLayoutParams);
		newIngredient.setLayoutParams(ingredientLayoutParams);

		newAmount.setHint(activity.getString(R.string.amount_placeholder));
		newIngredient.setHint(activity.getString(R.string.ingredient_placeholder));
		
		newAmount.setEms(10);
		newIngredient.setEms(10);
		newAmount.setSingleLine(true);
		newIngredient.setSingleLine(true);
		
		amountIngredientTuple.addView(newAmount);
		amountIngredientTuple.addView(newIngredient);
		
		return new IngredientControlTuple(amountIngredientTuple, newAmount, newIngredient);
	}
}
